//
//  PresentationController.swift
//  SwiftWB
//
//  Created by 远成物流 on 2017/6/26.
//
//

import UIKit

class PresentationController: UIPresentationController {
    
    lazy var cover:UIView = UIView()
    var presentedFrame = CGRect.zero
    
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        
        //设置弹出框的frame
        presentedView?.frame = presentedFrame
        
        //添加蒙版
        setupCoverView()
    }
}

///Mark - 设置UI
extension PresentationController{
    func setupCoverView() {
        
        containerView?.insertSubview(cover, at: 0)
        
        cover.frame = containerView!.bounds
        cover.backgroundColor = UIColor(white:0.8 , alpha:0.2)
        
        let tap = UITapGestureRecognizer(target: self, action: #selector(coverViewClick))
        cover.addGestureRecognizer(tap)
    }
}

///Mark - 点击事件
extension PresentationController{
    @objc func coverViewClick(){
        presentedViewController.dismiss(animated: true, completion: nil)
    }
}
